package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.OrderMapper;
import com.itheima.pojo.dto.OrderDTO;
import com.itheima.pojo.entity.Order;
import com.itheima.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImp implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    @Override
    public PageResult findPageOrder(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<Order> list=orderMapper.selectAll();
        PageInfo<Order> orderPageInfo = new PageInfo<>(list);
        return new PageResult(orderPageInfo.getTotal(),orderPageInfo.getList());
    }

    @Override
    public void updateOrder(OrderDTO orderDTO) {
        Order order = new Order();
        BeanUtils.copyProperties(orderDTO,order);
        orderMapper.updateOrder(order);
    }
}
